package com.association.interceptor;

import com.alibaba.fastjson.JSON;
import com.association.model.vo.CourierTokenBean;
import com.association.service.UserService;
import com.association.utils.RequestTokenBeanLocal;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author admin
 */
@Component
public class UserInterceptor implements HandlerInterceptor {
    private static Logger logger = LoggerFactory.getLogger(UserInterceptor.class);

    public static final String USER_CODE = "userCode";
    public static final String USER_NAME = "userName";
    public static final String PROJECT_CODE = "projectCode";
    public static final String ORG_NAME = "orgName";
    private static final String YZ_LOGIN_NUM = "yzLoginNum";
    private static final String DEVICE_TYPE = "deviceType";
    public static final String TOKEN_HEADER = "token";
    public static final String DEVICE_NO = "deviceNo";
    public static final String APPVERSION_NO = "appVersionNo";
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userCode = request.getHeader(USER_CODE);
        String userName = request.getHeader(USER_NAME);
        String projectCode = request.getHeader(PROJECT_CODE);
        String orgName = request.getHeader(ORG_NAME);
        String yzLoginNum = request.getHeader(YZ_LOGIN_NUM);
        String deviceType = request.getHeader(DEVICE_TYPE);
        String token = request.getHeader(TOKEN_HEADER);
        String deviceNo = request.getHeader(DEVICE_NO);
        String versionNo = request.getHeader(APPVERSION_NO);
        System.out.println(userCode);

        CourierTokenBean courierTokenBean;
        courierTokenBean = new CourierTokenBean(userCode, userName, projectCode);
        RequestTokenBeanLocal.set(courierTokenBean);

        return true;
    }



}
